package com.jushu.storbox.entities;

import android.content.ContentValues;
import android.database.Cursor;

public class NodeFiles {
	/**table name*/
	public static final String TABLE_NANME_4_CHANGE_METADATA = "files_inode";
		
	public static class Fields {
		/**fields*/
	    public static final String ID = "id";
	    public static final String PARENTID = "parentId";
	    public static final String TYPE = "type";
	    public static final String STATUS = "status";
	    public static final String SIZE = "size";
	    public static final String NAME = "name";
	    public static final String SHA1 = "sha1";
	    public static final String OBJECT_ID = "objectId";
	    public static final String CREATED_AT = "createdAt";
	    public static final String MODIFIED_AT = "modifiedAt";
	    public static final String CONTENT_CREATED_AT = "contentCreatedAt";
	    public static final String CONTENT_MODIFIED_AT = "contentModifiedAt";
	    public static final String SYNC_VERSION = "syncVersion";
	    public static final String SYNC_STATUS = "syncStatus";
	    
	    /**table command*/
	    public static final String sql4CreateTable = "CREATE TABLE IF NOT EXISTS "
	            + TABLE_NANME_4_CHANGE_METADATA + " " + "("
	            + ID + " bigint(20) NOT NULL," 
	            + PARENTID+ " bigint(20) NOT NULL," 
	            + TYPE + " tinyint(4) NOT NULL," 
	            + STATUS + " tinyint(4) NOT NULL," 
	            + NAME + " varchar(255) NOT NULL," 
	            + SIZE + " bigint(20) NOT NULL," 
	            + SHA1 + " varchar(64) default NULL," 
	            + OBJECT_ID + " varchar(32) default NULL," 
	            + CREATED_AT + " datetime default NULL," 
	            + MODIFIED_AT + " datetime default NULL," 
	            + CONTENT_CREATED_AT + " datetime default NULL," 
	            + CONTENT_MODIFIED_AT + " datetime default NULL," 
	            + SYNC_VERSION + " bigint(32) NOT NULL,"
	            + SYNC_STATUS + " bigint(32) NOT NULL"
	        + ")";
	}
	
    private Integer id;
    
    private Integer parentId;
    
    private Integer type;
    
     /** 0:nomal, 1:creating, 2:recycled, 3:parent is recycled, 4:deleted */
    private Integer status;
    
    private String name;
    
    private Integer size;
    
    private String sha1;
    
    private String objectId;
    
    private String createdAt;
    
    private String modifiedAt;
    
    private String contentCreatedAt;
    
    private String contentModifiedAt;
    /** is nodes has out link */
    private Integer syncVersion;
	/** sync status on server */
	private Integer syncStatus;
    
    public Integer getId()
    {
        return id;
    }
    
    public String getStringId()
    {
    	if(id != null) {
    		return id.toString();
    	}
        return "";
    }
    
    public void setId(Integer id)
    {
        this.id = id;
    }
    
    public Integer getParentId()
    {
        return parentId;
    }
    
    public void setParentId(Integer parentId)
    {
        this.parentId = parentId;
    }
    
    public Integer getType()
    {
        return type;
    }
    
    public void setType(Integer type)
    {
        this.type = type;
    }
    
    public Integer getStatus()
    {
        return status;
    }
    
    public void setStatus(Integer status)
    {
        this.status = status;
    }
    
    public String getName()
    {
        return name;
    }
    
    public void setName(String name)
    {
        this.name = name;
    }
    
    public Integer getSize()
    {
        return size;
    }
    
    public void setSize(Integer size)
    {
        this.size = size;
    }
    
    public String getSha1()
    {
        return sha1;
    }
    
    public void setSha1(String sha1)
    {
        this.sha1 = sha1;
    }
    
    public String getObjectId()
    {
        return objectId;
    }
    
    public void setObjectId(String objectId)
    {
        this.objectId = objectId;
    }
    
    public String getCreatedAt()
    {
        return createdAt;
    }
    
    public void setCreatedAt(String createdAt)
    {
        this.createdAt = createdAt;
    }
    
    public String getModifiedAt()
    {
        return modifiedAt;
    }
    
    public void setModifiedAt(String modifiedAt)
    {
        this.modifiedAt = modifiedAt;
    }
    
    public String getContentCreatedAt()
    {
        return contentCreatedAt;
    }
    
    public void setContentCreatedAt(String contentCreatedAt)
    {
        this.contentCreatedAt = contentCreatedAt;
    }
    
    public String getContentModifiedAt()
    {
        return contentModifiedAt;
    }
    
    public void setContentModifiedAt(String contentModifiedAt)
    {
        this.contentModifiedAt = contentModifiedAt;
    }
    
    public int getSyncVersion()
    {
        return syncVersion;
    }
    
    public void setSyncVersion(Integer syncVersion)
    {
        this.syncVersion = syncVersion;
    }

	public Integer getSyncStatus() {
		return syncStatus;
	}

	public void setSyncStatus(Integer syncStatus) {
		this.syncStatus = syncStatus;
	}
    
    @Override
    public String toString()
    {
        return "FilesINode [id=" + id + ", parentId=" + parentId + ", type=" + type
            + ", status=" + status + ", name=" + name + ", size=" + size + ", sha1=" + sha1 + ", objectId="
            + objectId + ", createdAt=" + createdAt + ", modifiedAt=" + modifiedAt + ", contentCreatedAt="
            + contentCreatedAt + ", contentModifiedAt=" + contentModifiedAt + ", syncVersion=" + syncVersion
            + "]";
    }
    
    public ContentValues toContentValues() {
		ContentValues values = new ContentValues();
		values.put(Fields.ID, getId());
		values.put(Fields.PARENTID, getParentId());
		values.put(Fields.TYPE, getType());
		values.put(Fields.STATUS, getStatus());
		values.put(Fields.NAME, getName());
		values.put(Fields.SIZE, getSize());
		values.put(Fields.SHA1, getSha1());
		values.put(Fields.OBJECT_ID, getObjectId());
		values.put(Fields.CREATED_AT, getCreatedAt());
		values.put(Fields.MODIFIED_AT, getModifiedAt());
		values.put(Fields.CONTENT_CREATED_AT, getContentCreatedAt());
		values.put(Fields.CONTENT_MODIFIED_AT, getContentModifiedAt());
		values.put(Fields.SYNC_VERSION, getSyncVersion());
		values.put(Fields.SYNC_STATUS, getSyncStatus());
		return values;
	}

	/** can read dbfile from server */
	public void fromCursor(Cursor cursor) {
		setId(cursor.getInt(cursor.getColumnIndex(Fields.ID)));
		setParentId(cursor.getInt(cursor.getColumnIndex(Fields.PARENTID)));
		setType(cursor.getInt(cursor.getColumnIndex(Fields.TYPE)));
		setStatus(cursor.getInt(cursor.getColumnIndex(Fields.STATUS)));
		setName(cursor.getString(cursor.getColumnIndex(Fields.NAME)));
		setSize(cursor.getInt(cursor.getColumnIndex(Fields.SIZE)));
		setSha1(cursor.getString(cursor.getColumnIndex(Fields.SHA1)));
		setObjectId(cursor.getString(cursor.getColumnIndex(Fields.OBJECT_ID)));
		setCreatedAt(cursor.getString(cursor.getColumnIndex(Fields.CREATED_AT)));
		setModifiedAt(cursor.getString(cursor.getColumnIndex(Fields.MODIFIED_AT)));
		setContentCreatedAt(cursor.getString(cursor.getColumnIndex(Fields.CONTENT_CREATED_AT)));
		setContentModifiedAt(cursor.getString(cursor.getColumnIndex(Fields.CONTENT_MODIFIED_AT)));
		setSyncVersion(cursor.getInt(cursor.getColumnIndex(Fields.SYNC_VERSION)));
		setSyncStatus(cursor.getInt(cursor.getColumnIndex(Fields.SYNC_STATUS)));
	}

}
